C     Program EX_0805.FOR
C     Listing 17F - see documentation in TUTOR.SSS
 
$include:'SSSF1.H'
 
      subroutine prime
$include:'SSSF2.H'
      integer TIMEL, REPTME
      character*5 a0
      integer*1 i(5)
      common TIMEL, REPTME, a0
      equivalence (a0, i)
      i(1) = 27
      i(2) = 91
      i(3) = 55
      i(4) = 57
      i(5) = 68
      TIMEL = 120
      REPTME = -1
      call INIQUE(1, 1, 1)
      call INISTA(1,'bus                   ',1,0,0,0)
      call TALLY(1, 1)
      call CREATE(0, 0)
      call CREATE(TIMEL, REPTME)
      return
      end
 
      subroutine signal
$include:'SSSF2.H'
      integer TIMEL, REPTME
      character*5 a0
      common TIMEL, REPTME, a0
      write(*,'(A,F6.2,A\)')'Simulated time ',T(),a0
      return
      end
 
      Program EX_0805
$include:'SSSF2.H'
      integer TIMEL, REPTME
      character*5 a0
      common TIMEL, REPTME, a0
      integer ARRIVL, STARTA, ENDACT, NEXTAC, REPORT,
     +  SSIZE, n, server, ecode, countr
      data  ARRIVL/1/, STARTA/2/, ENDACT/3/, NEXTAC/4/
      data  REPORT/5/, SSIZE/4/
      data  n/0/, server/1/, countr/0/
 
      call prime
 
   99 ecode = NEXTEV()
      if (ecode.gt.0) then
        goto (101, 102, 103, 104, 105) ecode
 
C ARRIVL
  101   continue
        if (IDE().eq.REPTME) then
          call SCHED(0, REPORT, IDE())
        else
          n = n + 1
          call signal
          call SETA(1, EX(0.9))
          call CREATE(EX(1), n)
          call SCHED(0, NEXTAC, IDE())
        endif
        goto 99
 
C NEXTAC
  104   continue
        if (server.gt.0) then
          call SCHED(0.0, STARTA, IDE())
        else
          call QUEUE(1, 0.0)
        endif
        goto 99
 
C STARTA
  102   continue
        call SCHED(A(1), ENDACT, IDE())
        server = server - 1
        call TALLY(1, server)
        goto 99
 
C REPORT
  105   continue
        call SCHED(TIMEL, REPORT, IDE())
        if (countr.eq.0) then
           write(*,'(A)')' # average avail.s         '
         else
           write(*,'(A,I1,F8.1,F8.3,A)')' ',countr,
     +       QAVG(1),SAVG(1),'                '
         endif
         call CLEARQ(1)
         call CLEARS(0)
         countr = countr + 1
         if (countr.gt.SSIZE) call SIMEND(0)
        goto 99
 
C ENDACT
  103   continue
        call DISPOS
        server = server + 1
        call TALLY(1, server)
        if (NQ(1).gt.0) then
          call REMVFQ(1, 1)
          call SCHED(0.0, STARTA, IDE())
        endif
        goto 99
 
      else
        stop 'End of simulation'
      endif
      end
 